import os   
import logging

from agent.domain.base import BaseDomain
from agent.common.system import sysCommand

logger = logging.getLogger('common')

class File(BaseDomain):
    __domain__ = "file"
    
    def __init__(self):
        super().__init__(domain_name = self.__domain__)
        
    def set_value(self, param_name: str, param_value):
        assert os.path.exists(param_name)
        assert not os.path.isdir(param_name)
        
        sysCommand("echo {value} > {file_path}".format(
            value = param_value,
            file_path = param_name
        ), log=True)
    
    def get_value(self, param_name: str):
        assert os.path.exists(param_name)
        assert not os.path.isdir(param_name)
        
        sysCommand("cat {file_path}".format(
            file_path = param_name
        ), log=True)

if __name__ == "__main__":
    handler = File()
    handler.set_value("/proc/sys/vm/dirty_expire_centisecs", "700")
    handler.get_value("/proc/sys/vm/dirty_expire_centisecs")